package com.qyhl.shop.shop.rush.detail;

import android.view.KeyEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.gyf.immersionbar.ImmersionBar;
import com.qyhl.shop.R;
import com.qyhl.shop.R2;
import com.qyhl.webtv.basiclib.base.BaseActivity;
import com.qyhl.webtv.basiclib.base.BaseIViewPresenter;
import com.qyhl.webtv.commonlib.constant.ARouterPathConstant;

import butterknife.BindView;
import butterknife.OnClick;

@Route(path = ARouterPathConstant.SHOP_RUSH_PURCHASE_RESULT)
public class ShopRushPurchaseResultActivity extends BaseActivity {
    @BindView(R2.id.message_txt)
    TextView messageTxt;
    @BindView(R2.id.status_tag)
    ImageView statusTag;
    @BindView(R2.id.result_btn)
    TextView resultBtn;
    @BindView(R2.id.coupon_btn)
    TextView couponBtn;

    @Autowired(name = "type")
    int type;// 1 成功  2 失败   3 抢光

    @Autowired(name = "id")
    int userGiftId;

    private final static int RESULT_CODE = 20;

    private final static int RESULT_OVER = 30;


    @Override
    protected int getContentView() {
        return R.layout.shop_activity_rush_purchase_result;
    }

    @Override
    protected void setImmersionBar(ImmersionBar mImmersionBar) {
        setDefaultImmerBar();
    }

    @Override
    protected BaseIViewPresenter initBaseIViewPresenter() {
        return null;
    }

    @Override
    protected void init() {
        switch (type) {
            case 1:
                couponBtn.setVisibility(View.VISIBLE);
                messageTxt.setText("恭喜你，成功抢到！");
                statusTag.setImageResource(R.drawable.shop_rush_purchase_success_icon);

                resultBtn.setText("完成");
                break;
            case 2:
                messageTxt.setText("抱歉，抢购失败！");
                statusTag.setImageResource(R.drawable.shop_rush_purchase_fail_icon);
                resultBtn.setText("再次抢购");
                break;
            case 3:
                messageTxt.setText("很遗憾，已抢空！");
                statusTag.setImageResource(R.drawable.shop_rush_purchase_empty_icon);
                resultBtn.setText("完成");
                break;
        }
    }

    @Override
    protected void setListener() {

    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            setResult(RESULT_OK);
            finish();
        }
        return super.onKeyDown(keyCode, event);
    }

    @OnClick({R2.id.back_btn, R2.id.coupon_btn, R2.id.result_btn})
    public void onClick(View view) {
        int viewId = view.getId();
        if (viewId == R.id.back_btn) {
            setResult(RESULT_OK);
            finish();
        } else if (viewId == R.id.coupon_btn) {
            if (userGiftId != 0) {
                ARouter.getInstance()
                        .build(ARouterPathConstant.SHOP_GIFT_DETAIL)
                        .withInt("id", userGiftId)
                        .navigation();
            }
        } else if (viewId == R.id.result_btn) {
            if (type == 1) {
                setResult(RESULT_OK);
            } else if (type == 3) {
                setResult(RESULT_OVER);
            } else if (type == 2) {
                setResult(RESULT_CODE);
            }
            finish();
        }
    }

}
